package com.qqt.csr.workbench.vo.resp;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.qqt.csr.workbench.entity.SkillSet;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(name = "SkillSetListRespVO", description = "技能组列表")
public class SkillSetListRespVO implements Serializable {
    @Serial
    private static final long serialVersionUID = -521873712158179886L;

    /**
     * 主键
     */
    @Schema(description = "主键id")
    private Long id;

    /**
     * 名称
     */
    @Schema(description = "名称")
    private String name;

    /**
     * 上级
     */
    @Schema(description = "上级")
    private Long parentId;

    /**
     * 排序值
     */
    @Schema(description = "排序值")
    private Integer sortNum;

    /**
     * 子级
     */
    @Schema(description = "子级")
    private List<SkillSetListRespVO> childList;

    public static SkillSetListRespVO of(SkillSet skillSet) {
        return SkillSetListRespVO.builder()
                .id(skillSet.getId())
                .parentId(skillSet.getParentId())
                .name(skillSet.getName())
                .sortNum(skillSet.getSortNum())
                .childList(skillSet.getChildList().stream().map(SkillSetListRespVO::of).collect(Collectors.toList()))
                .build();
    }
}
